package com.java.main.controller.work;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import com.java.main.controller.work.WorkInput;
import com.java.main.domain.token.TokenDO;
import com.java.main.domain.work.WorkDO;
import com.java.main.service.token.TokenService;
import com.java.main.service.user.UserService;
import com.java.main.service.work.WorkService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.java.main.constant.Errors;
import com.java.main.controller.BaseController;
import com.java.main.controller.input.DataInput;
import com.java.main.controller.output.BaseOutput;
import com.java.main.controller.output.ResultResponseBeanUtil;
import com.java.main.domain.KbmContent;

import com.java.main.domain.user.UserDO;
import com.java.main.domain.user.UserEntryRepository;
import com.java.main.domain.user.UserRepository;
import com.java.main.exception.HiBabyGlobalException;

import com.java.main.util.StringUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value = "作品", description = "作品接口-王国栋", produces = "application/json")
@Controller
public class WorkController extends BaseController {
    private Logger log = LoggerFactory.getLogger(getClass());
    @Value("${encrypt_algorithm}")
    private String encryptAlgorithm;
    @Autowired
    private WorkService workService;


    @ApiOperation(value = "创建作品", notes = "保存作品")
    @ResponseBody
    @RequestMapping(value = "/work/create", method = RequestMethod.POST)
    public BaseOutput<Void> createWork(@Valid @RequestBody WorkInput input) {
        WorkDO workDO = new WorkDO();
        workDO.setName(input.getName());
        workDO.setData(input.getData());
        workDO.setUserId(1); // 当前用户的id

        workService.saveWork(workDO);
        return ResultResponseBeanUtil.success();
    }

    @ApiOperation(value = "作品列表", notes = "作品列表")
    @ResponseBody
    @RequestMapping(value = "/work/create", method = RequestMethod.POST)
    public BaseOutput<Void> workList(HttpServletRequest request) {
        // 获取用户列表
        return ResultResponseBeanUtil.success();
    }




//    @ApiOperation(value = "用户注册", notes = "用户注册")
//    @ResponseBody
//    @RequestMapping(value = "/user/signup", method = RequestMethod.POST)
//    public BaseOutput<LoginOutput> signup(@Valid @RequestBody LoginInput input) {
//
//        UserDO userDO = userService.findByUserAccount(input.getUserAccount());
//        // 用户已存在
//        if (userDO != null) {
//            throw new HiBabyGlobalException(Errors.USER_EXISTED);
//        }
//        UserDO entity = userService.createUser(input.getMobile(),input.getUserAccount(),input.getPassword());
//        //	用户创建失败
//        if (entity == null) {
//            throw new HiBabyGlobalException(Errors.SIGN_UP_ERROR);
//        }
//        // if (entity.getStatus() == 1) {
//        // throw new HiBabyGlobalException(Errors.NOT_PERMISSION, "禁止登录");
//        // }
//
//        LoginOutput output = new LoginOutput();
//        output.setUserAccount(entity.getUserAccount());
//        output.setMobile(entity.getMobile());
//
//        return ResultResponseBeanUtil.success(output);
//    }
//
//    @ApiOperation(value = "验证用户登录状态", notes = "验证用户登录状态")
//    @ResponseBody
//    @RequestMapping(value = "/user/isLogin", method = RequestMethod.POST)
//    public BaseOutput<LoginOutput> isLogin(HttpServletRequest request) {
//        // 能进来验证就证明token有效,
//        String userToken = request.getHeader("USER-TOKEN");
//        TokenDO tokenDO = tokenService.findByToken(userToken);
//
//        UserDO userDO = userService.findById(tokenDO.getUserId());
//        // 用户不存在
//        if (userDO == null) {
//            tokenService.deleteTokenDObyToken(userToken);
//            throw new HiBabyGlobalException(Errors.NOT_LOGIN);
//        }
//
//        LoginOutput output = new LoginOutput();
//        output.setUserAccount(userDO.getUserAccount());
//        output.setMobile(userDO.getMobile());
//        return ResultResponseBeanUtil.success(output);
//    }
}
